#!/usr/bin/python3
# _*_ coding: utf-8 _*_
#
# Copyright (C) 2024 - 2024 heihieyouheihei, Inc. All Rights Reserved 
#
# @Time    : 2024/8/23 23:06
# @Author  : Yuyun
# @File    : leetcode_20_有效的括号.py
# @IDE     : PyCharm




class Solution:
    #   栈实现
    def valid_parentheses(self, pares):
        stack = []
        for pare in pares:
            if pare == '(':
                stack.append(')')
            elif pare == '[':
                stack.append(']')
            elif pare == '{':
                stack.append('}')
            #   若最新括号不与{、[、( 匹配；或者括号一直为}、]、）导致stack一直为空，则不符合要求
            #   此处必须先判断是否为空，因为如果pop()操作再判断会影响结果
            elif stack[-1] != pare or not stack:
                return False
            #   若最新括号匹配，则将栈最后一位推出。直到遍历所有括号后，栈中所有括号推出，即符合要求
            else:
                stack.pop()
        return True if not stack else False

    #   字典+栈 实现
    def valid_parentheses_I(self, pares):
        stack = []
        mapping = {'(': ')', '[': ']', '{': '}'}
        for pare in pares:
            if pare in mapping.keys():
                stack.append(mapping[pare])
            elif stack[-1] != pare or not stack:
                return False
            else:
                stack.pop()
        return True if not stack else False

if __name__ == '__main__':
    parentheses = input()
    solution = Solution()
    result = solution.valid_parentheses(parentheses)
    print(result)